<template>
  <div class="app-container">
    <el-form ref="form" :model="house" label-width="120px">
      <!--    隐藏域 记录id-->
      <input type="hidden" v-model="house.id"/>
      <el-form-item label="房间号">
        <el-input v-model="house.room"/>
      </el-form-item>
      <el-form-item label="楼层">
        <el-input v-model="house.floor"/>
      </el-form-item>
      <el-form-item label="单元">
        <el-input v-model="house.unit"/>
      </el-form-item>
      <el-form-item label="楼栋">
        <el-input v-model="house.building"/>
      </el-form-item>
      <el-form-item label="区域">
        <el-input v-model="house.area"/>
      </el-form-item>
      <el-form-item>
        <el-button type="primary"  @click="onSubmit">修改房屋</el-button>
        <el-button @click="onCancel">取消</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
import request from '@/utils/request'
export default {
  data() {
    return {
      house: {
        id:0,
        room: '',
        floor: '',
        unit: '',
        building: '',
        area: ''
      }
    }
  },
  mounted() {
    this.house=this.$store.state.user.house;
  },
  methods: {
    onSubmit() {
      // 请求接口 实现用户新增接口的调用
      request({
        url:"http://127.0.0.1:8080/api/house/update.do",
        method: "POST",
        data:this.house
      }).then(res=>{
        if(res.code==0){
          //跳转到列表页面
          this.$router.push("/houselist");
        }
      })
    },
    onCancel() {
      this.$message({
        message: 'cancel!',
        type: 'warning'
      })
    }
  }
}
</script>

<style scoped>
.line{
  text-align: center;
}
</style>

